<?php

	$logid=GetLoginUserID();
	if(isset($_GET['uid'])&&intval($_GET['uid'])>0)
	{
		$uid=intval($_GET['uid']);
	}
	else
	{
		if($logid!=false)
			$uid=$logid;
		else
			edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));
	}

	$userDAO=GetUserDAO();
	$user=$userDAO->GetUserByID($uid);	
	if(!$user)
		edp_redirect(edp_href_link(PAGENAME_PAGE_NOT_FOUND));

	$cityDAO=GetCityDAO();
	
	/*
	 * 用户统计信息
	 */
	$userStatistic=$userDAO->GetStatisticByUid($uid);
		
	/*
	 * 用户详细信息
	 */
	$userDetailInfo=$userDAO->GetUserDetailInfo($uid);
	
	/*
	 * 访客记录(已优化)
	 */
	if($logid&&$logid!=$uid)
	{
		$userDAO->AddVisitHistory($uid, $logid);	
		$userDAO->AddVisitorCountByUid($uid);
	}
	$visitUserList=$userDAO->GetVisitHistoryByUid($uid);
	
	/*
	 * 最近的点评
	 * 
	 */
	
	$reviewDAO=GetReviewDAO();
	$reviewList = $reviewDAO->GetRecentReviewByUid($uid,2);
	
	/*
	 * 最近添加评单
	 */
	$listDAO=GetListDAO();
	$listList=$listDAO->GetListByUid($uid, 10);
	
	/*
	 * 最近收藏店铺
	 */
	$collectDAO=GetCollectionDAO();
	$collectshopList=$collectDAO->GetCollectionShopByUid($uid, 10);
	
	/*
	 * 最近添加店铺
	 */
	$shopDAO=GetShopDAO();
	$addshopList=$shopDAO->GetShopByUid($uid, 10);
	
	/*
	 * 最近添加商品
	 */
	$productDAO=GetProductDAO();
	$addproductList=$productDAO->GetProductByUid($uid, 10);
	
	
	
	/*
	 * 最近事件(最好用ajax来显示)
	 */
	
	$eventList=$userDAO->GetEventByUid($uid, 25);

	if($eventList!=false)
	{
		foreach($eventList as $key=>$event)
		{
			$action = explode(',',$event['action']);
			
			switch ($action[0])
			{
				case REGISTER:
				{
					$event['html']="在本站注册。";
					break;
				}
				case INVITE_FRIEND_SUCCESS:
				{
					$inviteduser=$userDAO->GetUserByID($event['parameters']);
					if($inviteduser!=false)
					{
						$event['html']='成功邀请用户 <a href="'.edp_href_link(PAGENAME_USER_INFO,'uid='.$event['parameters']).'">'.
						$inviteduser['nick'].'</a> 注册。';
					}
					break;
				}
				case CREATE_LIST:
				{
					$list=$listDAO->GetListByLid($event['parameters']);
					if($list!=false)
					{
						$event['html']='创建评单 <a href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.
						$list['title'].'</a>。';
					}
					break;
				}
				case COLLECT_LIST:
				{
					$list=$listDAO->GetListByLid($event['parameters']);
					if($list!=false)
					{
						$event['html']='收藏评单 <a href="'.edp_href_link(PAGENAME_LIST_INFO,'lid='.$event['parameters']).'">'.
						$list['title'].'</a>。';
					}
					break;
				}
								
				//Review about shop
				case NORMAL_REVIEW:
				{
					$idlist=split(' ',$event['parameters']);
					
					$is_picture='';
					
					$is_first='';

					foreach($action as $k=>$v){
						
						if($v==REVIEW_INCLUDE_PIC){
							
							$is_picture = '[图]';
						}
						if($v==FIRST_REVIEW){
							
							$is_first = '第一次';
						}
					}					
					
					if(isset($idlist[2])){
						//存在product_id,表示是在商品页面发表的点评，显示商品信息
					
						$productName=$productDAO->GetProductName($idlist[2]);
						if($productName!=false)
						{
							$event['html']='对商品 <a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist[2]).'">'.$productName.'</a> 发表'.$is_first.'评论。'.$is_picture;
						}
						
					}else{
						
						//不存在product_id,表示是在店铺页面发表的点评，显示店铺信息
						$shopName=$shopDAO->GetShopName($idlist[0]);
						if($shopName!=false)
						{
							$event['html']='对店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist[0]).'">'.$shopName.'</a> 发表'.$is_first.'评论。'.$is_picture;
						}
					
					}
		
					break;
				}

				case ADD_SHOP:
				{
					$shopName = $shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='添加店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a>。';
					}
					break;
				}
				case ADD_PRODUCT:
				{
					$idlist=split(' ',$event['parameters']);
					$shopName=$shopDAO->GetShopName($idlist['0']);
					$productDAO=GetProductDAO();
					$product=$productDAO->GetProductInfo($idlist['1']);
					if($shopName!=false&&$product!=false)
					{
						$event['html']='添加店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.
						$shopName.'</a> 的商品';
						if(strlen($product['product_name'])>'20')
							$product['product_name']=EdpSubStr($product['product_name'], '0', '20').'...';
						$event['html']=$event['html'].'<a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.
						$product['product_name'].'</a>';
						$event['html']=$event['html'].'。';
					}
					break;
				}
				case ADD_FRIEND:
				{
					$adduser=$userDAO->GetUserByID($event['parameters']);
					if($adduser!=false)
					{
						$event['html']='与用户 <a href="'.edp_href_link(PAGENAME_USER_INFO,'uid='.$event['parameters']).'">'.
						$adduser['nick'].'</a> 成为好友。';
					}
					break;
				}
				case COLLECT_SHOP:
				{
					$shopName=$shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='收藏店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a>。';
					}
					break;
				}
				case COLLECT_PRODUCT:
				{
					$idlist=split(' ',$event['parameters']);
					$shopName = $shopDAO->GetShopName($idlist['0']);
					$productDAO=GetProductDAO();
					$product=$productDAO->GetProductInfo($idlist['1']);
					if($shopName!=false&&$product!=false)
					{
						$event['html']='收藏店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$idlist['0']).'">'.
						$shopName.'</a> 的商品 ';
						if(strlen($product['product_name'])>'20')
							$product['product_name']=EdpSubStr($product['product_name'], '0', '20').'...';
						$event['html']=$event['html'].'<a href="'.edp_href_link(PAGENAME_PRODUCT_INFO,'pid='.$idlist['1']).'">'.
						$product['product_name'].'</a>';
						$event['html']=$event['html'].'。';
					}
					break;
				}
				case MODIFY_SHOP:
				{
					$shopName = $shopDAO->GetShopName($event['parameters']);
					if($shopName!=false)
					{
						$event['html']='修改店铺 <a href="'.edp_href_link(PAGENAME_SHOP_INFO,'sid='.$event['parameters']).'">'.
						$shopName.'</a> 的简介。';
					}
					break;
				}
				default:
					break;
			}
			$eventStr[]=$event;
		}
	}
	
?>